/*
NOTES TO DATA CLEANING:
	* Rename and label variables and values
	* Recode don't know, refused to answer, phone cut as missing values
	* Check for outliers and inconsistencies
	* Create "FLAG" in the notes for the variable if there are inconsistencies or outliers
	* Create relevant dummy variables, drop irrelevant variables
	* Organize data by modules
*/

clear all
set more off
capture log close


********************************************************************************
use "$covidclean/SMS_merged_data.dta", clear

*Define global labels for values
la def yn 1"Yes" 0"No"

count //12799
count if consent==1 //4043

***MODULE A: DEMOGRAPHICS
	
	la var district "District"
	note district: "What is the name of the district you are currently in?"
	la def district 1 "Saran" 8 "Other" 555 "Phone cut"
	la val district district
	tab district, mi //15 phone cuts, 4028 responded
	recode district (555=.)
	//majority from Saran
	
		gen byte saran = district == 1 if ~missing(district)
		la var saran "District - Saran"
		order saran, a(district)

	la var district_oth "District - other"
	note district_oth: "District - other"
	note district_oth: "FLAG: CLEAN RESPONDENTS AS OUTSIDE THE DISTRICT OR OUTSIDE THE STATE"
	tab district_oth, mi
		
		/*Clean districts as either outside the district but same state or different state
		gen district_oth1 = ""
		replace district_oth1 = "Jharkhand" if regexm(district_oth, "khand") | regexm(district_oth, "Ranchi")
		replace district_oth1 = "Assam" if inlist(district_oth, "Asam") | regexm(district_oth, "Assa") | regexm(district_oth, "Aasam") | regexm(district_oth, "asam")
		replace district_oth1 = "Gujarat" if regexm(district_oth, "Guj") | regexm(district_oth, "guj")| regexm(district_oth, "Bhuj") | ///
											 inlist(district_oth, "Surat", "Ahamadabad")
		replace district_oth1 = "Delhi" if regexm(district_oth, "elhi") | regexm(district_oth, "Dehli")
		replace district_oth1 = "Odisha" if regexm(district_oth, "Udisa") | regexm(district_oth, "Odhisa")
		replace district_oth1 = "Maharashtra" if regexm(district_oth, "Mumbai") | regexm(district_oth, "Pune") | regexm(district_oth, "Maha") | ///
												 regexm(district_oth, "Aurngabad") | regexm(district_oth, "Puna") | regexm(district_oth, "Nasik") | ///
												 regexm(district_oth, "Nagpur")
		replace district_oth1 = "Haryana" if inlist(district_oth, "Fridabad") | regexm(district_oth, "yan")
		replace district_oth1 = "Chandigarh" if regexm(district_oth, "Chandi")
		replace district_oth1 = "Rajasthan" if inlist(district_oth, "Jaipur") | regexm(district_oth, "Jodh")
		replace district_oth1 = "Sikkim" if inlist(district_oth, "Shikim") | regexm(district_oth, "Sikm")
		replace district_oth1 = "Karnataka" if regexm(district_oth, "Karna") | regexm(district_oth, "Bang")
		replace district_oth1 = "Punjab" if regexm(district_oth, "dhar") | regexm(district_oth, "njab") | regexm(district_oth, "udhi")
		replace district_oth1 = "Chattisgarh" if regexm(district_oth, "Chh") | regexm(district_oth, "hatish")
		replace district_oth1 = "Uttar Pradesh" if inlist(district_oth, "Up") | regexm(district_oth, "(up)") | inlist(district_oth,"Noyada") | ///
												   regexm(district_oth, "u.p") | regexm(district_oth, "Panip")
		replace district_oth1 = "Telangana" if inlist(district_oth, "rabad") | regexm(district_oth, "tela")
		replace district_oth1 = "West Bengal" if regexm(district_oth, "kata")
		replace district_oth1 = "Himachal Pradesh" if regexm(district_oth, "simla") | regexm(district_oth, "Himachal") 
		replace district_oth1 = "Madhya Pradesh" if regexm(district_oth, "Madh")
		replace district_oth1 = "Tamil Nadu" if regexm(district_oth, "Tamil")
		replace district_oth1 = "Different district (same state)" if inlist(district_oth, "Ara", "Arariya", "Patna", "Siwan", "Katihar", "Samastipur", "Samstipur") | ///
																	 inlist(district_oth, "Veshali", "Vaishali", "Nalanda", "Gaya", "Sitamarhi", "Jamui", "Banka") | ///
																	 inlist(district_oth, "Bhagalpur", "Begusarai") | regexm(district_oth,"Muzza") | ///
																	 regexm(district_oth,"Muza") | regexm(district_oth,"ffar") | regexm(district_oth,"atna") | ///
																	 regexm(district_oth,"mparan")
		l district_oth district_oth1 if district==8
		*/
		
	la var location "Location"
	note location: "Are you currently in a city, in a town, or in a rural area?"
	la def location 1 "City" 2 "Town" 3 "Rural Area" 99 "Refuse to answer" 555 "Phone cut"
	la val location location
	tab location, mi //42 phone cuts, 4001 responded (3 refuse to answer)
	recode location (99 555=.)
	//majority from rural location

		tab location, gen(location_)
		local locations `""City" "Town" "Rural Area""'
		forval i=1/3 {
			local location : word `i' of `locations'
			la var location_`i' "Location - `location'"
			replace location_`i'=. if missing(location)
			la val location_`i' yn
			tab location_`i', mi
		}
		order location_*, a(location)

	la var whereabout "Location of the respondent"
	note whereabout: "Could you tell me where you are now?"
	la def whereabout 1 "In my house" 2 "In my relative's or friend's house" 3 "Somewhere else outside (shop, farm, etc.)" 99 "Refuse to answer" 555 "Phone cut"
	la val whereabout whereabout
	tab whereabout, mi //68 phone cuts, 3975 responded (7 refuse to answer)
	recode whereabout (99 555=.)
	//majority are in the house; or somewhere else outside
	
		tab whereabout, gen(whereabout_)
		local whereabouts `""Respondent in his/her house" "Respondent in his/her relatives or friends house" "Respondent somewhere else outside""'
		forval i=1/3 {
			local whereabout : word `i' of `whereabouts'
			la var whereabout_`i' "`whereabout'"
			replace whereabout_`i'=. if missing(whereabout)
			la val whereabout_`i' yn
			tab whereabout_`i', mi
		}
		order whereabout_*, a(whereabout)

	la var withwhom "Anyone with the respondent"
	note withwhom: "Could you tell me who else is near you now?"
	la def withwhom 1 "Nobody is near me right now" 2 "My immediate family member" 3 "Friend or relative" 8 "Others" 99 "Refuse to answer" 555 "Phone cut"
	la val withwhom withwhom
	tab withwhom, mi //101 phone cuts, 3942 responded (13 refuse to answer)
	recode withwhom (99 555=.)
	//majority are alone; or with immediate family member
	
		tab withwhom, gen(withwhom_)
		local withwhoms `""Nobody" "Immediate family" "Friend or relative" "Others""'
		forval i=1/4 {
			local withwhom : word `i' of `withwhoms'
			la var withwhom_`i' "`withwhom' near the respondent"
			replace withwhom_`i'=. if missing(withwhom)
			la val withwhom_`i' yn
			tab withwhom_`i', mi
		}
		order withwhom_*, a(withwhom)

	la var age "Age"
	note age: "How old are you? NOTE: End interview if age < 18 years of age"
	count if age<18 //112
	summ age
	tab age, mi //88 phone cuts, 3955 responded (35 don't know/refuse to answer)
	recode age (555 -999 -888 -99 99 = .)

	la var gender "Gender"
	note gender: "What is your gender?"
	la def gender 1 "Male" 2 "Female" 8 "Others" 99 "Refuse to answer" 555 "Phone cut"
	la val gender gender
	tab gender, mi //91 phone cuts, 3840 responded (1 don't know/refuse to answer)
	recode gender (99 555=.)
	tab gender if age<18
	//majority male

		gen byte male = gender == 1 if ~missing(gender)
		la val male yn
		la var male "Male"
		tab male, mi
		order male, a(gender)

	la var education "Highest level of school attended"
	note education: "What is the highest level of school you attended?"
	la def education 1 "Never been to school" 2 "Primary" 3 "Secondary" 4 "Higher" 8 "Other" 99 "Refuse to answer" 555 "Phone cut"
	la val education education
	tab education, mi //117 phone cuts, 3814 responded (17 don't know/refuse to answer)
	recode education (99 555=.)
	//majority higher education; or other; or secondary
	
		tab education, gen(educ_)
		local educations `""Never been to school" "Completed primary schooling" "Completed secondary schooling" "Completed above secondary schooling" "Completed other schooling""'
		forval i=1/5 {
			local education : word `i' of `educations'
			la var educ_`i' "`education'"
			replace educ_`i'=. if missing(education)
			la val educ_`i' yn
			tab educ_`i', mi
		}
		order educ_*, a(education)

	la var occupation "Occupation"
	note occupation: "What is your occupation, that is, what kind of work do you mainly do?"
	la def occupation 0 "Not in work force/no occupation" 1 "Professional/technical/managerial" 2 "Clerical" 3 "Sales" 5 "Agricultural" 7 "Services/household and domestic" 8 "Manual - skilled and unskilled" 88 "Others" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val occupation occupation
	tab occupation, mi //136 phone cuts, 3795 responded (23 don't know/refuse to answer)
	//majority manual or no job
	recode occupation (98 99 555=.)
	
		tab occupation, gen(occ_)
		local occs `""Unemployed" "Professional/technical/managerial job" "Clerical job" "Sales job" "Agricultural job" "Services/household and domestic job" "Manual job - skilled and unskilled" "Other jobs""'
		forval i=1/8 {
			local occ : word `i' of `occs'
			la var occ_`i' "`occ'"
			replace occ_`i'=. if missing(occupation)
			la val occ_`i' yn
			tab occ_`i', mi
		}
		order occ_*, a(occupation)

	la var demos_c "Demographics: Comments"
	note demos_c: "Demographics: Comments"
	tab demos_c, mi
	note demos_c: "FLAG: HAS INFORMATION ON THE JOB TYPE OF RESPONDENTS, NEED TO CLEAN"
		/*
		gen byte occ_9 = 1 if regexm(demos_c, "ASHA") | regexm(demos_c, "ANM") | regexm(demos_c, "sha")
		tab occ_9
		*/

	la var caste "Caste"
	note caste: "What is your caste?"
	la def caste 1 "General category" 2 "Scheduled Castes" 3 "Scheduled Tribes" 4 "Other Backward Classes" 5 "Nomadic" 8 "Others" 99 "Refuse to answer" 98 "Don’t know" 555 "Phone cut"
	la val caste caste
	tab caste, mi
	//majority OBC; SC
	recode caste (98 99 555=.)
	
		tab caste, gen(caste_)
		local castes `""General category" "Scheduled Castes" "Scheduled Tribes" "Other Backward Classes" "Nomadic Tribes" "Other castes""'
		forval i=1/6 {
			local caste : word `i' of `castes'
			la var caste_`i' "`caste'"
			replace caste_`i'=. if missing(caste)
			la val caste_`i' yn
			tab caste_`i', mi
		}
		order caste_*, a(caste)

	la var religion "Religion"
	note religion: "What is your religion?"
	la def religion 1 "Hindu" 2 "Muslim" 3 "Christian" 4 "Sikh" 8 "Others" 99 "Refuse to answer" 98 "Don’t know" 555 "Phone cut"
	la val religion religion
	tab religion, mi
	//majority hindu; muslim
	recode religion (98 99 555=.)
	
		tab religion, gen(religion_)
		local religions `""Hindu" "Muslim" "Christian" "Other religion""'
		forval i=1/4 {
			local religion : word `i' of `religions'
			la var religion_`i' "`religion'"
			replace religion_`i'=. if missing(religion)
			la val religion_`i' yn
			tab religion_`i', mi
		}
		order religion_*, a(religion)

	tab demos2_c, mi
	drop demos2_c
	
	*Organize the module variables
	global demographics district saran district_oth location location_1 location_2 location_3 whereabout whereabout_1 whereabout_2 whereabout_3 withwhom withwhom_1 withwhom_2 withwhom_3 withwhom_4 age gender male education educ_1 educ_2 educ_3 educ_4 educ_5 occupation occ_1 occ_2 occ_3 occ_4 occ_5 occ_6 occ_7 occ_8 demos_c caste caste_1 caste_2 caste_3 caste_4 caste_5 caste_6 religion religion_1 religion_2 religion_3 religion_4
	order $demographics
	gen DEMOGRAPHICS = "*****DEMOGRAPHICS*****"
	la var DEMOGRAPHICS"*****DEMOGRAPHICS*****"
	order DEMOGRAPHICS, b(district)
	
	tab phonecut_sec1 //136, 3907

***KNOWLEDGE OF SYMPTOMS - 11 SYMPTOMS (UNPROMPTED)

	count if symptoms!="" //3795 responded
	
	la var symptoms "Signs and symptoms of Coronavirus"
	note symptoms: "Can you tell me what the signs and symptoms of Coronavirus are?"
	tab symptoms, mi 
	drop symptoms

	rename symptoms_1 know_cough
	rename symptoms_2 know_fever
	rename symptoms_3 know_breathe
	rename symptoms_4 know_headache
	rename symptoms_5 know_sneeze
	rename symptoms_6 know_fatigue
	rename symptoms_7 know_aches
	rename symptoms_8 know_throat
	rename symptoms_9 know_diarrhea
	rename symptoms_10 know_congestion
	rename symptoms_11 know_smell
	rename symptoms_88 know_sym_oth
	rename symptoms_others know_sym_oth_s

	la var know_cough "Know symptom: Coughing"
	la var know_fever "Know symptom: Fever"
	la var know_breathe "Know symptom: Difficulty breathing"
	la var know_headache "Know symptom: Headache"
	la var know_sneeze "Know symptom: Sneezing/Runny nose"
	la var know_fatigue "Know symptom: Fatigue/Tiredness"
	la var know_aches "Know symptom: Body aches"
	la var know_throat "Know symptom: Sore throat"
	la var know_diarrhea "Know symptom: Diarrhea"
	la var know_congestion "Know symptom: Nasal and throat congestion"
	la var know_smell "Know symptom: Loss of smell and taste"
	la var know_sym_oth "Know symptom: Others"
	la var know_sym_oth_s "Know symptom: Others (specified)"


	foreach v of varlist know_cough-know_sym_oth {
		tab `v', mi
		la val `v' yn
	}
	//fever and cough are more salient symptoms
	
	tab know_sym_oth_s, mi
	note know_sym_oth_s: "FLAG: STILL NEEDS TO BE CLEANED"
	
	*Variable for number of symptoms recalled by the respondent 
	egen know_sym_n = rowtotal(know_cough-know_smell), missing
	summ know_sym_n
	tab know_sym_n, mi
	la var know_sym_n "Know symptom: Total number"
	
	*Dummy for any symptom recalled
	gen byte know_sym_any = know_sym_n > 0 if ~missing(know_sym_n)
	la var know_sym_any "Know symptom: Any"
	la val know_sym_any yn
	tab know_sym_any

	tab symptoms_c, mi
	tab symptoms_555 //89 phone cuts
	
	drop symptoms_c symptoms_98 symptoms_99 symptoms_555

	*Organize the module variables
	global symptoms know_sym_any know_sym_n know_cough know_fever know_breathe know_headache know_sneeze know_fatigue know_aches know_throat know_diarrhea know_congestion know_smell know_sym_oth know_sym_oth_s
	gen SYMPTOMS = "*****KNOWLEDGE OF SYMPTOMS (UNPROMPTED)*****"
	la var SYMPTOMS "*****KNOWLEDGE OF SYMPTOMS (UNPROMPTED)*****"
	order SYMPTOMS $symptoms, a(religion_4)
	
***KNOWLEDGE OF PROTECTIVE BEHAVIOR (UNPROMPTED)

	count if protection!="" | protection2!="" //3705 responded
	
	la var protection "According to you, what are the methods of protection against the virus?"
	note protection: "According to you, what are the methods of protection against the virus?"
	tab protection, mi

	la var protection2 "According to you, what are the methods of protection against the virus?"
	note protection2: "According to you, what are the methods of protection against the virus?"
	tab protection2, mi
		
	*Check for random order of the knowledge question versus action question (unprompted)
	tab ques_order_hb, mi
	rename ques_order_hb know_behavior_order 
	la var know_behavior_order "Question on knowledge of COVID behavior asked first"
	recode know_behavior_order (2 = 0)
	la val know_behavior_order yn
	tab know_behavior_order, mi
	
	*Combine two protection variables (given the order for knowledge and use was randomized) into one based on the variable "know_behavior_order"
	foreach i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 88 98 99 555 {
		count if missing(protection_`i') & ~missing(protection2_`i')
		replace protection_`i' = protection2_`i' if know_behavior_order == 0
	}
	
	rename protection_1 know_hwonly
	rename protection_2 know_hwsoap
	rename protection_3 know_cover
	rename protection_4 know_notouch
	rename protection_5 know_avoidcrowds
	rename protection_6 know_sd
	rename protection_7 know_nospit
	rename protection_8 know_masksick
	rename protection_9 know_mask
	rename protection_10 know_avoidcontact
	rename protection_11 know_avoidobjects
	rename protection_12 know_avoidsickobjects
	rename protection_13 know_clean
	rename protection_14 know_stayhome
	rename protection_15 know_noshake
	rename protection_16 know_sanitizer
	rename protection_88 know_beh_oth
	rename protection_others know_beh_oth_s
	
	la var know_hwonly "Know behavior: Wash hands frequently"
	la var know_hwsoap "Know behavior: Wash hands frequently with soap"
	la var know_cover "Know behavior: Respiratory hygiene"
	la var know_notouch "Know behavior: Don’t touch eyes, nose, or mouth"
	la var know_avoidcrowds "Know behavior: Avoid crowded places"
	la var know_sd "Know behavior: Distancing"
	la var know_nospit "Know behavior: Don’t spit in public"
	la var know_masksick "Know behavior: Wear a mask if sick"
	la var know_mask "Know behavior: Wear a mask"
	la var know_avoidcontact "Know behavior: Avoid physical contact with infected individuals"
	la var know_avoidobjects "Know behavior: Avoid touching common surfaces, items or sharing plates/utensils"
	la var know_avoidsickobjects "Know behavior: Avoid touching what sick persons have touched such as surfaces, items, plates/utensils"
	la var know_clean "Know behavior: Keep cleaning common surfaces"
	la var know_stayhome "Know behavior: Stay at home"
	la var know_noshake "Know behavior: Don’t shake hands with others"
	la var know_sanitizer "Know behavior: Using hand sanitizer"
	la var know_beh_oth "Know behavior: Others"
	la var know_beh_oth_s "Know behavior: Others (specified)"
	
	foreach v of varlist know_hwonly - know_sanitizer {
		tab `v', mi
		la val `v' yn
	}
	//majority report sd, mask, hand sanitizer
	
	replace know_beh_oth_s = know_beh_oth_s if know_behavior_order == 0
	tab know_beh_oth_s, mi
	note know_beh_oth_s: "FLAG: STILL NEEDS TO BE CLEANED"
	
	*Variable for number of behavior recalled by the respondent 
	egen know_beh_n = rowtotal(know_hwonly - know_sanitizer), missing
	summ know_beh_n
	tab know_beh_n, mi
	la var know_beh_n "Know behavior: Total number"
	
	*Dummy for any behavior recalled
	gen byte know_beh_any = know_beh_n > 0 if ~missing(know_beh_n)
	la var know_beh_any "Know behavior: Any"
	la val know_beh_any yn
	tab know_beh_any, mi
		
	*Key outcome of interest (Unprompted)
		
		*Social distancing 
		tab know_sd, mi
		
		*Hand washing
		gen byte know_hw = (know_hwonly == 1 | know_hwsoap == 1)
		replace know_hw = . if missing(know_hwonly) & missing(know_hwsoap)
		tab know_hw, mi			
		la var know_hw "Know behavior: Hand washing"

	*Organize the module variables
	drop protection protection_98 protection_99 protection_555 protection2-protection2_others
	global knowledge know_behavior_order know_beh_any know_beh_n know_sd know_stayhome know_avoidcrowds know_hw know_hwonly know_hwsoap know_cover know_notouch know_nospit know_masksick know_mask know_avoidcontact know_avoidobjects know_avoidsickobjects know_clean know_noshake know_sanitizer know_beh_oth know_beh_oth_s
	gen KNOWLEDGE_BEHAVIOR = "*****KNOWLEDGE - PREVENTIVE BEHAVIOR (UNPROMPTED)*****"
	la var KNOWLEDGE_BEHAVIOR "*****KNOWLEDGE - PREVENTIVE BEHAVIOR (UNPROMPTED)*****"
	order KNOWLEDGE_BEHAVIOR $knowledge, a(know_sym_oth_s)
	
***TAKE UP OF PROTECTIVE BEHAVIOR (UNPROMPTED)

	count if protection_use!="" | protection_use2!="" //3705 responded

	la var protection_use "What are you doing to protect against the virus?"
	note protection_use: "What are you doing to protect against the virus?"
	tab protection_use, mi

	la var protection_use2 "What are you doing to protect against the virus?"
	note protection_use2: "What are you doing to protect against the virus?"
	tab protection_use2, mi
	
	*Combine two protection_use variables (given the order for knowledge and use was randomized) into one based on the variable "know_behavior_order"
	foreach i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 88 98 99 555 {
		count if missing(protection_use_`i') & ~missing(protection_use2_`i')
		replace protection_use_`i' = protection_use2_`i' if know_behavior_order == 0
	}
	
	rename protection_use_1 act_hwonly
	rename protection_use_2 act_hwsoap
	rename protection_use_3 act_cover
	rename protection_use_4 act_notouch
	rename protection_use_5 act_avoidcrowds
	rename protection_use_6 act_sd
	rename protection_use_7 act_nospit
	rename protection_use_8 act_masksick
	rename protection_use_9 act_mask
	rename protection_use_10 act_avoidcontact
	rename protection_use_11 act_avoidobjects
	rename protection_use_12 act_avoidsickobjects
	rename protection_use_13 act_clean
	rename protection_use_14 act_stayhome
	rename protection_use_15 act_noshake
	rename protection_use_16 act_sanitizer
	rename protection_use_88 act_beh_oth
	rename protection_use_others act_beh_oth_s

	la var act_hwonly "Action: Wash hands frequently"
	la var act_hwsoap "Action: Wash hands frequently with soap"
	la var act_cover "Action: Respiratory hygiene"
	la var act_notouch "Action: Don’t touch eyes, nose, or mouth"
	la var act_avoidcrowds "Action: Avoid crowded places"
	la var act_sd "Action: Distancing"
	la var act_nospit "Action: Don’t spit in public"
	la var act_masksick "Action: Wear a mask if sick"
	la var act_mask "Action: Wear a mask"
	la var act_avoidcontact "Action: Avoid physical contact with infected individuals"
	la var act_avoidobjects "Action: Avoid touching common surfaces, items or sharing plates/utensils"
	la var act_avoidsickobjects "Action: Avoid touching what sick persons have touched such as surfaces, items, plates/utensils"
	la var act_clean "Action: Keep cleaning common surfaces"
	la var act_stayhome "Action: Stay at home"
	la var act_noshake "Action: Don’t shake hands with others"
	la var act_sanitizer "Action: Using hand sanitizer"
	la var act_beh_oth "Action: Others"
	la var act_beh_oth_s "Action: Others (specified)"

	foreach v of varlist act_hwonly - act_sanitizer {
		tab `v', mi
		la val `v' yn
	}
	//majority report sd, mask, hand sanitizer
	
	replace act_beh_oth_s = act_beh_oth_s if know_behavior_order == 0
	tab act_beh_oth_s, mi
	note act_beh_oth_s: "FLAG: STILL NEEDS TO BE CLEANED"
	
	*Variable for number of behavior recalled by the respondent 
	egen act_beh_n = rowtotal(act_hwonly - act_sanitizer), missing
	summ act_beh_n
	tab act_beh_n, mi
	la var act_beh_n "Action: Total number"
	
	*Dummy for any behavior recalled
	gen byte act_beh_any = act_beh_n > 0 if ~missing(act_beh_n)
	la var act_beh_any "Action: Any"
	la val act_beh_any yn
	tab act_beh_any, mi
		
	*Key outcome of interest (Unprompted)
		
		*Social distancing 
		tab act_sd, mi
		
		*Hand washing
		gen byte act_hw = (act_hwonly == 1 | act_hwsoap == 1)
		replace act_hw = . if missing(act_hwonly) & missing(act_hwsoap)
		tab act_hw, mi			
		la var act_hw "Action: Hand washing"

	*Organize the module variables
	drop protection_use protection_use_98 protection_use_99 protection_use_555 protection_use2-protection_use2_others
	global action act_beh_any act_beh_n act_sd act_stayhome act_avoidcrowds act_hw act_hwonly act_hwsoap act_cover act_notouch act_nospit act_masksick act_mask act_avoidcontact act_avoidobjects act_avoidsickobjects act_clean act_noshake act_sanitizer act_beh_oth act_beh_oth_s
	gen ACTION_BEHAVIOR = "*****ACTION - PREVENTIVE BEHAVIOR (UNPROMPTED)*****"
	la var ACTION_BEHAVIOR "*****ACTION - PREVENTIVE BEHAVIOR (UNPROMPTED)*****"
	order ACTION_BEHAVIOR $action, a(know_beh_oth_s)

***TAKE UP OF PROTECTIVE BEHAVIOR (PROMPTED)
	
	count if meeting<555 //3519 responded
	la var meeting "Prompted: Stepped outside house in last 2 days"
	note meeting: "Have you stepped outside of the house to meet anyone or for some other reason? For example, to meet someone in a group or for a meeting, get-together, or to go to the market or shopping."
	la def meeting 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val meeting meeting
	tab meeting, mi
	recode meeting (98 99 555 = .)
		
		tab meeting, gen(meeting_)
		local meetings `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local meeting : word `i' of `meetings'
			la var meeting_`i' "Prompted: Stepped outside house - `meeting'"
			replace meeting_`i'=. if missing(meeting)
			la val meeting_`i' yn
			tab meeting_`i', mi
		}
		order meeting_*, after(meeting)
	
	count if close_contact<555 //3503 responded
	rename close_contact contact 
	la var contact "Prompted: Within 2 arms distance with anyone in last 2 days"
	note contact: "Have you come into close contact with anyone not in your household, that is within 2 arms distance or less? For example, when you went to meet someone in a group or for a meeting, get-together, or to go to the market or shopping."
	la def contact 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val contact contact
	tab contact, mi
	recode contact (98 99 555 = .)
	
		tab contact, gen(contact_)
		local contacts `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local contact : word `i' of `contacts'
			la var contact_`i' "Prompted: Within 2 arms distance - `contact'"
			replace contact_`i'=. if missing(contact)
			la val contact_`i' yn
			tab contact_`i', mi
		}
		order contact_*, after(contact)
		
		*Generate outcome of interest whether unprompted or prompted
		gen any_sd = act_sd == 1 | contact == 3
		replace any_sd = . if missing(act_sd) & missing(contact)
		la val any_sd yn
		tab any_sd, mi
		la var any_sd "Maintained two arms distance (unprompted or prompted)"
		
	count if wear_mask<555 //3488 responded
	rename wear_mask mask 
	la var mask "Prompted: Worn mask in last 2 days"
	note mask: "Have you worn a face mask when you stepped outside of the house?"
	la def mask 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val mask mask
	tab mask, mi
	recode mask (98 99 555 = .)
	
		tab mask, gen(mask_)
		local masks `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local mask : word `i' of `masks'
			la var mask_`i' "Prompted: Worn mask - `mask'"
			replace mask_`i'=. if missing(mask)
			la val mask_`i' yn
			tab mask_`i', mi
		}
		order mask_*, after(mask)
	
	count if soap<555 //3470 responded
	rename soap washhands
	la var washhands "Prompted: Washed hands/Used sanitizer in last 2 days"
	note washhands: "Have you washed hands with soap and running water, or used hand sanitizer?"
	la def washhands 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val washhands washhands
	tab washhands, mi
	recode washhands (98 99 555 = .)
	
		tab washhands, gen(washhands_)
		local washhandss `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local washhands : word `i' of `washhandss'
			la var washhands_`i' "Prompted: Hand washing - `washhands'"
			replace washhands_`i'=. if missing(washhands)
			la val washhands_`i' yn
			tab washhands_`i', mi
		}
		order washhands_*, after(washhands)
		
	*Generate outcome of interest whether unprompted or prompted
		gen any_hw = act_hw == 1 | washhands == 1
		replace any_hw = . if missing(act_hw) & missing(washhands)
		la val any_hw yn
		tab any_hw, mi
		la var any_hw "Washed hands regularly (unprompted or prompted)"
	
	rename covering cover
	la var cover "Prompted: Respiratory hygiene"
	note cover: "have you covered your nose and mouth when you cough or sneeze?"
	la def cover 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val cover cover
	tab cover, mi
	recode cover (98 99 555 = .)
	
		tab cover, gen(cover_)
		local covers `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local cover : word `i' of `covers'
			la var cover_`i' "Prompted: Covered nose and mouth - `cover'"
			replace cover_`i'=. if missing(cover)
			la val cover_`i' yn
			tab cover_`i', mi
		}
		order cover_*, after(cover)
		
	*Organize the module variables
	global prompted meeting meeting_1 meeting_2 meeting_3 contact contact_1 contact_2 contact_3 mask mask_1 mask_2 mask_3 washhands washhands_1 washhands_2 washhands_3 cover cover_1 cover_2 cover_3 any_sd any_hw
	gen PROMPTED_BEHAVIOR = "*****ACTION - PREVENTIVE BEHAVIOR (PROMPTED)*****"
	la var PROMPTED_BEHAVIOR "*****ACTION - PREVENTIVE BEHAVIOR (PROMPTED)*****"
	order PROMPTED_BEHAVIOR $prompted, a(act_beh_oth_s)	
	
***TAKE UP OF PROTECTIVE BEHAVIOR BY COMMUNITY (PROMPTED)

	count if close_contact_comm<555 //3378

	rename close_contact_comm contact_c
	la var contact_c "Prompted: Community member - Close contact (within 2 arms distance) in last 2 days"
	note contact_c: "Have they come into close contact with anyone not in their household, that is within 2 arms distance or less?"
	la def contact_c 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val contact_c contact_c
	tab contact_c, mi
	recode contact_c (98 99 555 = .)
	
		tab contact_c, gen(contact_c_)
		local contact_cs `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local contact_c : word `i' of `contact_cs'
			la var contact_c_`i' "Prompted:  Community member - Close contact (within 2 arms distance) in last 2 days - `contact_c'"
			replace contact_c_`i'=. if missing(contact_c)
			la val contact_c_`i' yn
			tab contact_c_`i', mi
		}
		order contact_c_*, after(contact_c)
	
	rename wear_mask_comm mask_c
	la var mask_c "Prompted:  Community member - Worn mask in last 2 days"
	note mask_c: "Have they worn a face mask when they stepped outside of the house?"
	la def mask_c 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val mask_c mask_c
	tab mask_c, mi
	recode mask_c (98 99 555 = .)
	
		tab mask_c, gen(mask_c_)
		local mask_cs `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local mask_c : word `i' of `mask_cs'
			la var mask_c_`i' "Prompted:  Community member - Worn mask in last 2 days - `mask_c'"
			replace mask_c_`i'=. if missing(mask_c)
			la val mask_c_`i' yn
			tab mask_c_`i', mi
		}
		order mask_c_*, after(mask_c)

	rename soap_comm washhands_c
	la var washhands_c "Prompted:  Community member - Washed hands/Used sanitizer in last 2 days"
	note washhands_c: "Have they washed hands with soap and running water, or used hand sanitizer?"
	la def washhands_c 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val washhands_c washhands_c
	tab washhands_c, mi
	recode washhands_c (98 99 555 = .)
	
		tab washhands_c, gen(washhands_c_)
		local washhands_cs `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local washhands_c : word `i' of `washhands_cs'
			la var washhands_c_`i' "Prompted:  Community member - Washed hands/Used sanitizer in last 2 days - `washhands_c'"
			replace washhands_c_`i'=. if missing(washhands_c)
			la val washhands_c_`i' yn
			tab washhands_c_`i', mi
		}
		order washhands_c_*, after(washhands_c)
	
	rename covering_comm cover_c
	la var cover_c "Prompted:  Community member - Covered nose and mouth in last 2 days"
	note cover_c: "Have they covered their nose and mouth while coughing or sneezing?"
	la def cover_c 1 "Always" 2 "Sometimes" 3 "Never" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	la val cover_c cover_c
	tab cover_c, mi
	recode cover_c (98 99 555 = .)
	
		tab cover_c, gen(cover_c_)
		local cover_cs `""Always" "Sometimes" "Never""'
		forval i=1/3 {
			local cover_c : word `i' of `cover_cs'
			la var cover_c_`i' "Prompted:  Community member - Covered nose and mouth in last 2 days - `cover_c'"
			replace cover_c_`i'=. if missing(cover_c)
			la val cover_c_`i' yn
			tab cover_c_`i', mi
		}
		order cover_c_*, after(cover_c)
		
	tab healthbehaviors_c
	la var healthbehaviors_c "Prompted behavior: Comments"
	note healthbehaviors_c: "Prompted behavior: Comments"
	note healthbehaviors_c: "FLAG: NEEDS TO BE CLEANED"	
		
	*Organize the module variables
	global prompted_c contact_c contact_c_1 contact_c_2 contact_c_3 mask_c mask_c_1 mask_c_2 mask_c_3 washhands_c washhands_c_1 washhands_c_2 washhands_c_3 cover_c cover_c_1 cover_c_2 cover_c_3 healthbehaviors_c
	gen PROMPTED_BEHAVIOR_COMM = "*****ACTION - PREVENTIVE BEHAVIOR BY COMMUNITY (PROMPTED)*****"
	la var PROMPTED_BEHAVIOR_COMM "*****ACTION - PREVENTIVE BEHAVIOR BY COMMUNITY (PROMPTED)*****"
	order PROMPTED_BEHAVIOR_COMM $prompted_c, a(any_hw)	

***LIST EXPERIMENT

	// LIST EXPERIMENT:
	// Each ordering of the items in the list was collected in a separate variable
	// So here we combine the responses into one outcome variable, and record
	// the numbering for the order, in case that's of interest.
	// The ordering is a number between 1 and 6, corresponding to the 
	// ordering of different statements in the survey instrument

	gen list = .
	gen list_order = .
	forval i = 1/6 {
		tab statements_agree`i', mi
		replace list = statements_agree`i' if ~missing(statements_agree`i')
		replace list_order = `i' if ~missing(statements_agree`i')
		recode list (555=.)
	} 
	tab list, mi
	
	la var list "List experiment: number of agreed statements"
	la var list_order "List experiment: order of statements"
	la def list_order 1 "TV Phone Behavior" 2 "Behavior Phone TV" 3 "Phone TV Behavior" ///
					  4 "Behavior TV Phone" 5 "TV Behavior Phone" 6 "Phone Behavior TV"
	la val list_order list_order
	tab list_order, mi
	
	*Create list variables specific to targeted behavior
	tab list behavior
	gen byte list_sd = list if behavior == 1 & ~missing(list)
	tab list_sd, mi
	gen byte list_hw = list if behavior == 2 & ~missing(list)
	tab list_hw, mi
	
	la var list_sd "List experiment: Social distancing - number of agreed statements"
	la var list_hw "List experiment: Handwashing - number of agreed statements"
	
	*Organize the module variables
	forvalues i=1/6 {
		drop statements_agree`i' television`i' phone`i' handwashing`i' socialdistancing`i'
	}
	global list list list_order list_sd list_hw
	gen LISTEXPERIMENT = "*****LIST EXPERIMENT*****"
	la var LISTEXPERIMENT "*****LIST EXPERIMENT*****"
	order LISTEXPERIMENT $list, a(healthbehaviors_c)

***SMS-SPECIFIC VARIABLES

	count if yourphone<555 //3219

	rename yourphone phone 
	la var phone "Own phone"
	note phone: "Is this your phone?"
	la def phone 1 "Yes" 2 "No" 555 "Phone cut"
	la val phone phone
	recode phone (555 = .) (2 = 0)
	la val phone yn
	tab phone, mi

	la var smsread "Can read SMS in Hindi"
	note smsread: "Can you read SMS messages in Hindi?"
	la def smsread 1 "Yes" 2 "No" 555 "Phone cut"
	la val smsread smsread
	recode smsread (555 = .) (2 = 0)
	la val smsread yn
	tab smsread, mi
	
	la var smsreceive "Received COVID-related SMS"
	note smsreceive: "Did you receive any informational SMSs related to coronavirus on your phone in the last week?"
	la def smsreceive 1 "Yes" 2 "No" 98 "Don't know" 555 "Phone cut"
	la val smsreceive smsreceive
	tab smsreceive, mi
	recode smsreceive (98 555 = .) (2 = 0)
	la val smsreceive yn
	tab smsreceive, mi
	note smsreceive: "FLAG: 9 PERCENT OF OBSERVATIONS SAY DON'T KNOW HENCE A DROP IN THE OBSERVATIONS"

	rename messagescount smscount
	la var smscount "Number of COVID-related SMSs received"
	note smscount: "How many of these text messages or SMS did you receive in the last week?"
	summ smscount
	tab smscount
	recode smscount (99 555 999 = .) (250 = 25) (340 = 34)

	tab message_content, mi	
	rename message_content_1 smscontent_hwonly
	rename message_content_2 smscontent_hwsoap
	rename message_content_3 smscontent_cover
	rename message_content_4 smscontent_notouch
	rename message_content_5 smscontent_avoidcrowds
	rename message_content_6 smscontent_sd
	rename message_content_7 smscontent_nospit
	rename message_content_8 smscontent_masksick
	rename message_content_9 smscontent_mask
	rename message_content_10 smscontent_avoidcontact
	rename message_content_11 smscontent_avoidobjects
	rename message_content_12 smscontent_avoidsickobjects
	rename message_content_13 smscontent_clean
	rename message_content_14 smscontent_stayhome
	rename message_content_15 smscontent_noshake
	rename message_content_16 smscontent_sanitizer
	rename message_content_88 smscontent_oth
	rename message_content_others smscontent_oth_s

	la var smscontent_hwonly "SMS content: Wash hands frequently"
	la var smscontent_hwsoap "SMS content: Wash hands frequently with soap"
	la var smscontent_cover "SMS content: Cover nose and mouth with handkerchief/issue/elbow while coughing or sneezing"
	la var smscontent_notouch "SMS content: Don’t touch eyes, nose, or mouth"
	la var smscontent_avoidcrowds "SMS content: Avoid crowded places"
	la var smscontent_sd "SMS content: Distancing"
	la var smscontent_nospit "SMS content: Don’t spit in public"
	la var smscontent_masksick "SMS content: Wear a mask if sick"
	la var smscontent_mask "SMS content: Wear a mask"
	la var smscontent_avoidcontact "SMS content: Avoid physical contact with infected individuals"
	la var smscontent_avoidobjects "SMS content: Avoid touching common surfaces, items or sharing plates/utensils"
	la var smscontent_avoidsickobjects "SMS content: Avoid touching what sick persons have touched such as surfaces, items, plates/utensils"
	la var smscontent_clean "SMS content: Keep cleaning common surfaces"
	la var smscontent_stayhome "SMS content: Stay at home"
	la var smscontent_noshake "SMS content: Don’t shake hands with others"
	la var smscontent_sanitizer "SMS content: Using hand sanitizer"
	la var smscontent_oth "SMS content: Others"
	la var smscontent_oth_s "SMS content: Others (specified)"
	
	foreach v of varlist smscontent_hwonly-smscontent_oth {
		tab `v', mi
		la val `v' yn
	}
	//mask, sd, hw recall
	
		*Create a variable for recalling SMS content for handwashing
		gen smscontent_hw = smscontent_hwonly==1 | smscontent_hwsoap==1 if ~missing(message_content)
		la val smscontent_hw yn
		la var smscontent_hw "SMS content: Hand washing"
		tab smscontent_hw, mi
	
	tab smscontent_oth_s, mi
	note smscontent_oth_s: "FLAG: STILL NEEDS TO BE CLEANED"
	
	rename trust_inf smstrust
	la var smstrust "Trust information on SMS"
	note smstrust: "Do you trust this information"
	la def smstrust 1 "Yes" 2 "No" 98 "Don't know" 99 "Refuse to answer" 555 "Phone cut"
	tab smstrust, mi
	la val smstrust smstrust
	recode smstrust (98 99 555 = .) (2 = 0)
	la val smstrust yn

	rename smsfrequency smsfreq
	la var smsfreq "Times SMS was read last week"
	note smsfreq: "How many times in the last week did you read any SMS messages on this phone?"
	la def smsfreq 1 "Not at all" 2 "1-3 times" 3 "4-6 times" 4 "Every day" 8 "Others [specify]" 99 "Don’t know" 555 "Phone cut"
	la val smsfreq smsfreq
	tab smsfreq, mi
	//majority not at all, everyday
	recode smsfreq (99 555 = .)
	
		tab smsfreq, gen(smsfreq_)
		local smsfreqs `""Did not read SMS at all last week" "Read SMS 1-3 times last week" "Read SMS 4-6 times last week" "Read SMS every day last week" "Read SMS - other frequency""'
		forval i=1/5 {
			local smsfreq : word `i' of `smsfreqs'
			la var smsfreq_`i' "`smsfreq'"
			replace smsfreq_`i'=. if missing(smsfreq)
			la val smsfreq_`i' yn
			tab smsfreq_`i', mi
		}
		order smsfreq_*, a(smsfreq)
	
	rename smsfrequency_others smsfreq_oth
	la var smsfreq_oth "Times SMS was read last week (Others)"
	tab smsfreq_oth, mi
	note smsfreq_oth: "FLAG: STILL NEEDS TO BE CLEANED"

	tab sms_c, mi
	la var sms_c "SMS Module: Comments"
	note sms_c: "FLAG: STILL NEEDS TO BE CLEANED"
	
	*Organize the module variables
	drop message_content message_content_98 message_content_99 message_content_555
	global sms smsread smsreceive smscount smscontent_sd smscontent_stayhome smscontent_avoidcrowds smscontent_hw smscontent_hwonly smscontent_hwsoap smscontent_cover smscontent_notouch smscontent_nospit smscontent_masksick smscontent_mask smscontent_avoidcontact smscontent_avoidobjects smscontent_avoidsickobjects smscontent_clean smscontent_noshake smscontent_sanitizer smscontent_oth smscontent_oth_s smstrust smsfreq smsfreq_1 smsfreq_2 smsfreq_3 smsfreq_4 smsfreq_5 smsfreq_oth sms_c
	gen SMSRELATED = "*****SMS-RELATED*****"
	la var SMSRELATED "*****SMS-RELATED*****"
	order SMSRELATED $sms, a(list_hw)
	order phone, a(religion_4)

***RISK PERCEPTIONS

	count if sick_covid<555 //3085

	rename sick_covid risk_sick 
	la var risk_sick "Risk of getting sick with Coronavirus"
	note risk_sick: "What is the risk of you getting sick with coronavirus?"
	la def risk_sick 1 "Very low" 2 "Low" 3 "High" 4 "Very high" 555 "Phone cut"
	la val risk_sick risk_sick
	tab risk_sick, mi
	recode risk_sick (555 = .)
		
		gen byte risk_sick_h = risk_sick >= 3 if ~missing(risk_sick)
		la var risk_sick_h "High or very high risk of getting sick from Coronavirus"
		la val risk_sick_h yn
		tab risk_sick_h, mi
		
		order risk_sick_h, a(risk_sick)

	rename die_covid risk_die
	la var risk_die "Risk of dying from Coronavirus"
	note risk_die: "What is the risk of someone dying from coronavirus after being infected by it?"
	la def risk_die 1 "Very low" 2 "Low" 3 "High" 4 "Very high" 555 "Phone cut"
	la val risk_die risk_die
	tab risk_die, mi
	recode risk_die (555 = .)
	
		gen byte risk_die_h = risk_die >= 3 if ~missing(risk_die)
		la var risk_die_h "High or very high risk of dying from Coronavirus"
		la val risk_die_h yn
		tab risk_die_h, mi
		
		order risk_die_h, a(risk_die)
		
	tab zones_c, mi
	drop zones_c

	*Organize the module variables
	global risk risk_sick risk_sick_h risk_die risk_die_h
	gen RISKPERCEPTIONS = "*****RISK PERCEPTIONS*****"
	la var RISKPERCEPTIONS "*****RISK PERCEPTIONS*****"
	order RISKPERCEPTIONS $risk, a(sms_c)

***MARLOWE-CROWE SCALE

	la var mc1 "It is sometimes hard for me to go on with my work if I am not encouraged."
	note mc1: "It is sometimes hard for me to go on with my work if I am not encouraged."
	la def mc1 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc1 mc1

	la var mc2 "I sometimes feel resentful when I don't get my way."
	note mc2: "I sometimes feel resentful when I don't get my way."
	la def mc2 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc2 mc2

	la var mc3 "On a few occasions, I have given up doing something because I thought too little"
	note mc3: "On a few occasions, I have given up doing something because I thought too little of my ability."
	la def mc3 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc3 mc3

	la var mc4 "There have been times when I felt like rebelling against people in authority eve"
	note mc4: "There have been times when I felt like rebelling against people in authority even though I knew they were right."
	la def mc4 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc4 mc4

	la var mc5 "No matter who I'm talking to, I'm always a good listener."
	note mc5: "No matter who I'm talking to, I'm always a good listener."
	la def mc5 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc5 mc5

	la var mc6 "There have been occasions when I took advantage of someone."
	note mc6: "There have been occasions when I took advantage of someone."
	la def mc6 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc6 mc6

	la var mc7 "I'm always willing to admit it when I make a mistake."
	note mc7: "I'm always willing to admit it when I make a mistake."
	la def mc7 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc7 mc7

	la var mc8 "I sometimes try to get even rather than forgive and forget."
	note mc8: "I sometimes try to get even rather than forgive and forget."
	la def mc8 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc8 mc8

	la var mc9 "I am always courteous even to people who are disagreeable."
	note mc9: "I am always courteous even to people who are disagreeable."
	la def mc9 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc9 mc9

	la var mc10 "I have ever been irked when people expressed ideas very different from my own."
	note mc10: "I have ever been irked when people expressed ideas very different from my own."
	la def mc10 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc10 mc10

	la var mc11 "There have been times when I was quite jealous of the good fortune of others."
	note mc11: "There have been times when I was quite jealous of the good fortune of others."
	la def mc11 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc11 mc11

	la var mc12 "I am sometimes irritated by people who ask favors of me."
	note mc12: "I am sometimes irritated by people who ask favors of me."
	la def mc12 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc12 mc12

	la var mc13 "I have deliberately said something that hurt someone's feelings."
	note mc13: "I have deliberately said something that hurt someone's feelings."
	la def mc13 1 "Agree" 2 "Disagree" 555 "Phone cut"
	la val mc13 mc13
	
	la def agree 1"Agree" 0"Disagree"
	forval i = 1/13 {
		tab mc`i', mi
		recode mc`i' (555 = .) (2 = 0)
		la val mc`i' agree
	}
	
	tab mc_c
	drop mc_c
	
	*Create a simple SD score 
	gen sds = (mc1 == 0) + (mc2 == 0) + (mc3 == 0) + (mc4 == 0) + (mc5 == 1) + (mc6  == 0) + (mc7 == 1) + (mc8 == 0) + (mc9 == 1) + (mc10 == 1) + (mc11 == 0) + (mc12 == 0) + (mc13 == 0)
	replace sds = . if missing(mc1) & missing(mc2) & missing(mc3) & missing(mc4) & missing(mc5) & missing(mc6) & missing(mc7) & missing(mc8) & missing(mc9) & missing(mc10) & missing(mc11) & missing(mc12) 
	label var sds "Social Desirability Score (Simple sum)" 
	//irt 1pl mc* 
	
	*** Run IRT on SDS
	foreach var in mc1 mc2 mc3 mc4 mc6 mc8 mc11 mc12 mc13 {
		replace `var' = 1 - `var' if !missing(`var')
	}
	irt 1pl mc*
	predict sds_irt, latent
	egen nonmisssds = rownonmiss(mc*)
	replace sds_irt = . if nonmisssds == 0
	drop nonmisssds 
	label var sds_irt "Social Desirability Score (IRT)"
	
	*Organize the module variables
	global mc sds sds_irt mc1 mc2 mc3 mc4 mc5 mc6 mc7 mc8 mc9 mc10 mc11 mc12 mc13
	gen MARLOWECROWE = "*****MARLOWE CROWE SCALE*****"
	la var MARLOWECROWE "*****MARLOWE CROWE SCALE*****"
	order MARLOWECROWE $mc, a(risk_die_h)

***ACCESS TO ROUTINE HEALTH CARE

	la var pregnant "A hh member currently pregnant"
	note pregnant: "Is someone in your household currently pregnant?"
	la def pregnant 1 "Yes" 2 "No" 99 "Refuse to answer" 555 "Phone cut"
	la val pregnant pregnant
	tab pregnant, mi
	recode pregnant (99 555 = .) (2 = 0)
	la val pregnant yn
	
	la var pregnancy_care "Pregnant member received routine care"
	note pregnancy_care: "Over the past three months, have this person received routine pregnancy care?"
	la def pregnancy_care 1 "Yes" 2 "No" 99 "Refuse to answer" 98 "Don't know" 555 "Phone cut"
	la val pregnancy_care pregnancy_care
	tab pregnancy_care, mi
	recode pregnancy_care (98 99 555 = .) (2 = 0)
	la val pregnancy_care yn

	la var child "A hh member less than 1 year of age"
	note child: "Is there a child younger than 1 year in your household?"
	la def child 1 "Yes" 2 "No" 99 "Refuse to answer" 555 "Phone cut"
	la val child child
	tab child, mi
	recode child (99 555 = .) (2 = 0)
	la val child yn

	la var child_age "Age of child hh member (in months)"
	note child_age: "What is the child’s age in months?"
	summ child_age
	tab child_age
	recode child_age (555=.)
	
	rename immunization_care child_care
	la var child_care "Child received routine immunizations"
	note child_care: "Over the past three months, has this child received routine childhood immunizations?"
	la def child_care 1 "Yes" 2 "No" 99 "Refuse to answer" 98 "Don't know" 555 "Phone cut"
	la val child_care child_care
	tab child_care, mi
	recode child_care (98 99 555 = .) (2 = 0)
	la val child_care yn

	tab healthseeking_c
	drop healthseeking_c
	
	*Organize the module variables
	global care pregnant pregnancy_care child child_age child_care
	gen ROUTINECARE = "*****ROUTINE CARE*****"
	la var ROUTINECARE "*****ROUTINE CARE*****"
	order ROUTINECARE $care, a(mc13)
	
*List any pending tasks
notes list

*Create a dataset with others specify variables or text variables for cleaning
	
	preserve
	
	keep scrambledid district district_oth occupation demos_c know_sym* know_beh* act_beh_* healthbehaviors_c smscontent* smsfreq smsfreq_oth sms_c 
	
	save "$covidclean/clean_textvars.dta", replace
	
	restore
	
*Organize the dataset
	
	*Drop irrelevant variables
	drop time_01 time_02 time_03 time_04 seed suppquestion time_05 rand upper_bound1 num_draws1 random_draws1_count random_draw1_1 scaled_draw1_1 random_draw1_2 ///
		scaled_draw1_2 random_draw1_3 scaled_draw1_3 random_draw1_4 scaled_draw1_4 unique_draws1 time_06 time_07 random_draw1_5 scaled_draw1_5 random_draw1_6 ///
		scaled_draw1_6 random_draw1_7 scaled_draw1_7 random_draw1_8 scaled_draw1_8 note_covidknowledge note_actions note_community note_listexperiment ///
		note_smsintervention note_riskperceptions note_mcscale note_household note_thanks isvalidated v249 v250 v251 v252 v253 v254 scramble_id_reenter ///
		cal_scramble_id instanceid formdef_version key phonesurvey_script dist_info
		
	*Organize relevant variables by a few categories apart from survey modules
	
	*Identifier information - ID, stratum, round of interview, etc.
	gen IDENTIFIERS = "*****IDENTIFIERS*****"
	la var IDENTIFIERS "*****IDENTIFICATION VARIABLES*****"
	order IDENTIFIERS scrambledid enumerator blockid round roundofinterview stratum, first
	la var scrambledid "Unique ID"
	la var stratum "Stratum by SCST X Literacy"
	
	*Treatment and behavior related dummies
	gen TREATMENT = "*****TREATMENT VARIABLES*****"
	la var TREATMENT "*****TREATMENT VARIABLES*****"
	order TREATMENT treatment_pooled treatment_arm treatment_gain treatment_frame treatment_timing behavior behavior_sd behavior_hw behavior_treatment ///
			treatment_arm_1 treatment_arm_2 treatment_arm_3 treatment_arm_4 treatment_arm_5 treatment_arm_6 treatment_arm_7 treatment_arm_8 treatment_arm_9 ///
			treatment_arm_10 treatment_arm_11 ///
			treatment_gain_1 treatment_gain_2 treatment_gain_3 treatment_gain_4 /// 
			treatment_frame_1 treatment_frame_2 treatment_frame_3 treatment_frame_4 treatment_frame_5 treatment_frame_6 ///
			treatment_timing_1 treatment_timing_2 treatment_timing_3, a(stratum)
	
	*Key Survey related variables
	gen SURVEY_RELATED = "*****SURVEY RELATED*****"
	la var SURVEY_RELATED "*****SURVEY RELATED VARIABLES*****"
	order SURVEY_RELATED actualsurveydate threedayrecall fivedayrecall dayofinterview submissiondate starttime endtime duration call_status respond call_later call_status_others consent language complete notcomplete notcomplete_dttme attempts surveydate, a(treatment_timing_3)

	*Sample related information (from master datasets)
	gen SAMPLE_RELATED = "*****FROM MASTER SAMPLE*****"
	la var SAMPLE_RELATED "*****FROM MASTER SAMPLE*****"
	order SAMPLE_RELATED backupid pairnumber samplebatch state block centertype highlit highscst idate dateofdelivery dateofinterview day, a(surveydate)
	
	*SMS delivery reports from the provider
	gen SMSDELIVERYSTATUS = "*****SMSDELIVERYSTATUS*****"
	la var SMSDELIVERYSTATUS "*****SMS DELIVERY STATUS*****"
	order SMSDELIVERYSTATUS sms_send_attempts delivered_count delivered_frac failed_count failed_frac notdelivered_count notdelivered_frac sent_count sent_frac, ///
			a(child_care)
			
	*Other survey related variables (not very important but may be useful)
	gen SURVEY_OTHERRELATED = "*****SURVEY RELATED (OTHERS)*****"
	la var SURVEY_OTHERRELATED "*****SURVEY RELATED VARIABLES (OTHERS)*****"
	order SURVEY_OTHERRELATED module_1 module_2 module_3 module_4 module_5 module_6 module_7 duration_1 duration_2 duration_3 duration_4 duration_5 duration_6 ///
		surv_num exotel_ph_num surveyor_c consent_c surveyfilename total_consent id_call_success treatmentfilename sampleinfo notcalledyet interviewedearlier ///
		phonecut_sec1 phonecut_sec2 phonecut_sec3 phonecut_sec4 phonecut_sec5 phonecut_sec6 phonecut_sec7 phonecut_sec8, last

*Label and Save cleaned data
label data "Final clean data for analysis"
save "$covidclean/smscovid_clean.dta", replace

exit, clear
